<template>
  <!--对话框：选择废品单 -->
  <el-dialog v-dialogDrag v-dialogDragWidth :title="dialog_selectWaste.title"
             :visible.sync="dialog_selectWaste.visible"
             width="1100px">

    <!-- 检索条件 -->
    <el-form :model="dialog_selectWaste.queryParams"
             :inline="true" v-show="dialog_selectWaste.showSearch" label-width="68px">
      <!-- 物料名称 -->
      <el-form-item label="物料名称" prop="itemName">
        <el-input
          v-model="dialog_selectWaste.queryParams.itemName"
          placeholder="请输入物料名称"
          clearable
          size="small"
          @keyup.enter.native="getList_wastes"
        />
      </el-form-item>

      <!-- 物料编码 -->
      <el-form-item label="物料编码" prop="itemNum">
        <el-input
          v-model="dialog_selectWaste.queryParams.itemNum"
          placeholder="请输入物料编码"
          clearable
          size="small"
          @keyup.enter.native="getList_wastes"
        />
      </el-form-item>

      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="getList_wastes"
        >搜索
        </el-button>
      </el-form-item>
    </el-form>


    <!-- 列表 -->
    <el-table v-loading="loading" :data="dialog_selectWaste.wasteList" row-key="wasteUuid">
      <el-table-column label="单据时间" align="center" prop="docDt" width="150">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.docDt, '{y}-{m}-{d} {h}:{m}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="废品单号" align="center" prop="wasteDocNum" width="180"/>
      <el-table-column label="物料名称" align="center" prop="itemName" width="150"/>
      <el-table-column label="物料编码" align="center" prop="itemNum" width="180"/>
      <el-table-column label="计划号" align="center" prop="docNum" width="180"/>
      <el-table-column label="工序类型" align="center" prop="mesDictProcessType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.mes_dict_process_type" :value="scope.row.mesDictProcessType"/>
        </template>
      </el-table-column>
      <el-table-column label="工序名称" align="center" prop="mesDictProcessName">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.mes_dict_process_name" :value="scope.row.mesDictProcessName"/>
        </template>
      </el-table-column>
      <el-table-column label="工序内容" align="center" prop="processContent" width="120" :show-overflow-tooltip="true"/>
      <el-table-column label="工序符号" align="center" prop="mesDictProcessCode">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.mes_dict_process_code" :value="scope.row.mesDictProcessCode"/>
        </template>
      </el-table-column>
      <el-table-column label="废品数量" align="center" prop="wasteQty" />
      <el-table-column label="请选择" align="center" class-name="small-padding fixed-width" fixed="right">
        <template slot-scope="scope">
          <el-button type="success" plain
                     size="small"
                     icon="el-icon-check"
                     @click="selectWaste_done(scope.row)"
          ><span> 选择</span></el-button>
        </template>
      </el-table-column>
    </el-table>

    <!--废品单列表分页-->
    <pagination
      v-show="dialog_selectWaste.total>0"
      :total="dialog_selectWaste.total"
      :page.sync="dialog_selectWaste.queryParams.pageNum"
      :limit.sync="dialog_selectWaste.queryParams.pageSize"
      @pagination="getList_wastes"
    />

    <div slot="footer" class="dialog-footer">
      <el-button @click="dialog_hide_selectWaste">取 消</el-button>
    </div>

  </el-dialog>

</template>
<script>
  import { listWaste } from "@/api/qms/waste";
  export default {
  dicts: ['mes_dict_process_type', 'mes_dict_process_name', 'mes_dict_process_code'],
  data() {
    return {
      dialog_selectWaste: {
        visible: false,
        showSearch: true,
        title: "请选择废品单",
        total: 0,
        wasteList: [],
        queryParams:{
          itemName: null,
          itemNum: null,
          docNum: null,
        }
      },
      // 遮罩层
      loading: true,
      //废品单列表
      wasteList: [],
    };
  },
  methods: {
    /** 读取列表：物料 */
    getList_wastes() {
      this.loading = true;
      this.dialog_selectWaste.queryParams.docNum = this.docNum
      console.log(this.dialog_selectWaste.queryParams.docNum)
      listWaste(this.dialog_selectWaste.queryParams).then(response => {
        this.dialog_selectWaste.wasteList = response.rows;
        console.log(this.wasteList)
        this.dialog_selectWaste.total = response.total;
        this.loading = false;
      });
    },

    /**完成：选择废品单*/
    selectWaste_done(waste) {
      this.dialog_selectWaste.visible = false;
      this.$emit("ok", waste );
      console.log( waste )
    },

    /**对话框：显示 - 选择废品单*/
    showDialog_selectWasteForm() {
      this.getList_wastes()
      this.dialog_selectWaste.visible = true;
      this.dialog_selectWaste.title = "选择废品单";
    },

    /**对话框：隐藏 - 选择废品单*/
    dialog_hide_selectWaste() {
      this.dialog_selectWaste.visible = false;
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.dialog_selectWaste.queryParams.pageNum = 1;
      this.getList();
    },

    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },

  }
};
</script>
